package com.config;

import com.intercepter.LoginAndPermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//
@Component
@ConfigurationProperties(prefix = "server")
public class ConfigApplication extends WebMvcConfigurerAdapter implements ApplicationListener<EmbeddedServletContainerInitializedEvent>{



    private String ip;


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getHost(){
        return "http://"+ip;
    }

    @Override
    public void onApplicationEvent(EmbeddedServletContainerInitializedEvent embeddedServletContainerInitializedEvent) {
        System.out.println("host:"+getHost());
    }


    @Autowired
    private LoginAndPermissionInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则        
        // excludePathPatterns 用于排除拦截路径       
        registry.addInterceptor(loginInterceptor).addPathPatterns("/*");
    }
}




